package com.vertx.mall.store;

import com.vertx.core.annotation.data.Address;
import com.vertx.core.annotation.data.Query;
import com.vertx.core.common.ResultFormat;
import com.vertx.core.common.StatusCodeMsg;
import com.vertx.data.entity.SqlPropertyValue;
import com.vertx.data.mysql.AbstractSQL;
import com.vertx.data.utils.DbUtils;
import com.vertx.mall.model.User;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import java.util.ArrayList;
import java.util.List;

/**
 * 描述:数据层
 * 创建人:hzw
 * 创建时间: 2018/4/19 9:33
 **/
@Query(name = "indexStore")
public class IndexStore extends AbstractSQL<User> {

    @Override
    protected String tableName(){
        return "t_user";
    }

    @Override
    protected String primaryId() {
        return "id";
    }

    @Override
    protected String columns() {
        return " id AS id, name AS name,phone as phone";
    }

    @Override
    protected List<SqlPropertyValue<?>> propertyValue(User obj){
        List<SqlPropertyValue<?>> result = new ArrayList<>();
        result.add(new SqlPropertyValue<>("name",obj.getName()));
        result.add(new SqlPropertyValue<>("phone",obj.getPhone()));
        result.add(new SqlPropertyValue<>("id", obj.getId()));
        return result;
    }

    @Address(path = "index")
    public void test(JsonObject jsonObject,Message<JsonObject> handler){
       /* DbUtils.getJdbcClient().getConnection(db->{
            if(db.succeeded()){
               *//* getCount(db.result(),rsp->{
                    if(db.succeeded()){
                        handler.reply(rsp.result());
                    }else{
                        handler.fail(500,"fail");
                    }
                });*//*
                selectAll(db.result(),rsp->{
                    if(!rsp.succeeded()){
                        handler.reply(ResultFormat.format(StatusCodeMsg.C200,rsp.result()));
                    }else{
                        handler.reply(ResultFormat.formatAsNewArray(StatusCodeMsg.C1500));
                    }
                });
            }else{
                handler.fail(500,"fail");
            }
        });*/
    }

}
